home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD32 Gamer 13 / CD32 Gamer - 1995 - Issue 13.iso / c / devren.c < prev    next >
C/C++ Source or Header  |  1978-10-06  |  4KB  |  149 lines

  1. /***************************************************************/
  2. /*                                                             */
  3. /*                Device Renamer v1.5 21.8.1990                */
  4. /*                                                             */
  5. /*                  written by Stefan Rosewig                  */
  6. /*                                                             */
  7. /*                       PUBLIC DOMAIN                         */
  8. /*                                                             */
  9. /***************************************************************/
  10. /*                                                             */
  11. /*      Aufrufe :      cc devren                               */
  12. /*                     ln devren.o -lc                         */
  13. /*                                                             */
  14. /***************************************************************/
  15.  
  16.       /*   Was gebraucht wird   */
  17.  
  18. #include <exec/types.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/dosextens.h>
  21. #include <libraries/filehandler.h>
  22.  
  23. #define STR(x) (((char *)BADDR(x))+1)
  24.  
  25. extern struct DosLibrary *DOSBase;
  26. struct DeviceNode *DeviceNode;
  27. struct RootNode *RootNode;
  28. struct DosInfo *DosInfo;
  29.  
  30.       /*   Gebrauchsanleitung   */
  31.  
  32. usage()
  33. {
  34.    printf("DevRen v1.5 by STR\n");
  35.    printf("USAGE: DevRen <old> <new>   to rename devices\n");
  36.    printf("       DevRen -l            to list devices\n");
  37.    exit();
  38. }
  39.  
  40.       /*   Fehlermeldungen   */
  41.  
  42. fault(f,fehl)
  43. USHORT f;
  44. char *fehl;
  45. {
  46.    printf("ERROR!!! %d:   ",f);
  47.    switch (f)
  48.    {
  49.       case 1:
  50.          printf("unknown parameter %s\n",fehl);
  51.       break;
  52.       case 2:
  53.          printf("can't find old device %s:\n",fehl);
  54.       break;
  55.       case 3:
  56.          printf("device %s: already exists\n",fehl);
  57.       break;
  58.       case 4:
  59.          printf("<old> and <new> MUST have the same length\n");
  60.       break;
  61.       case 5:
  62.          printf("too many parameters\n");
  63.    }
  64.    exit();
  65. }
  66.  
  67.       /*   Suchen eines Devices   */
  68.  
  69. find(DeviceName)
  70. char *DeviceName;
  71. {
  72.    DeviceNode = (struct DeviceNode *)BADDR(DosInfo->di_DevInfo);
  73.    do
  74.    {
  75.       if (DeviceNode->dn_Type == (ULONG)DLT_DEVICE)          /*   Device ?   */
  76.       {
  77.          if (strcmp(STR(DeviceNode->dn_Name),DeviceName) == 0)
  78.             return(TRUE);                              /*  richtiger Name ?  */
  79.       }
  80.       DeviceNode = (struct DeviceNode *)BADDR(DeviceNode->dn_Next);
  81.    }
  82.    while (DeviceNode != 0L);                           /*   nicht gefunden   */
  83.    return (FALSE);
  84. }
  85.  
  86.       /*   Auflisten bekannter devices   */
  87.  
  88. liste()
  89. {
  90.    REGISTER USHORT x;
  91.    x = 0;
  92.    DeviceNode = (struct DeviceNode *)BADDR(DosInfo->di_DevInfo);
  93.    do
  94.    {
  95.       if (DeviceNode->dn_Type == (ULONG)DLT_DEVICE)
  96.       {
  97.          printf(" %s:   ",STR(DeviceNode->dn_Name));
  98.          x++;
  99.          if (x == 7)
  100.          {
  101.             printf("\n");
  102.             x = 0;
  103.          }
  104.       }
  105.       DeviceNode = (struct DeviceNode *)BADDR(DeviceNode->dn_Next);
  106.    }
  107.    while(DeviceNode != 0L);
  108.    printf("\n");
  109.    exit();
  110. }
  111.  
  112. main(argc,argv)
  113. int argc;
  114. char *argv[];
  115. {
  116.    REGISTER int l1,l2,x;
  117.    USHORT fehler;
  118.    char *fehlstr;
  119.    RootNode = (struct RootNode *)DOSBase->dl_Root;
  120.    DosInfo  = (struct DosInfo  *)BADDR(RootNode->rn_Info);
  121.    switch(argc)
  122.    {
  123.       case 1:
  124.          usage();
  125.       case 2:
  126.          if (strcmp(argv[1],"?")== 0) usage();
  127.          if ((strcmp(argv[1],"-l") == 0) || (strcmp(argv[1],"-L") == 0))
  128.             liste();
  129.          fault (1,argv[1]);
  130.       case 3:
  131.          l1 = strlen(argv[1]);
  132.          l2 = strlen(argv[2]);
  133.          if ( l1 != l2 ) fault(4,"");                /*  erlaubter Name ?  */
  134.          for (x = 0 ; x <= l1 ; x++)                 /*   Großbuchstaben   */
  135.          {
  136.             argv[1][x] = toupper(argv[1][x]);
  137.             argv[2][x] = toupper(argv[2][x]);
  138.          }
  139.          if (argv[1][l1-1] == ':') argv[1][l1-1] = '\0';   /*   ':' muß    */
  140.          if (argv[2][l2-1] == ':') argv[2][l2-1] = '\0';   /*  nicht sein  */
  141.          if (find(argv[2])) fault(3,argv[2]);    /* Device existiert schon */
  142.          if (!find(argv[1])) fault(2,argv[1]);   /* Device existiert nicht */
  143.          strcpy(STR(DeviceNode->dn_Name),argv[2]);    /*   Umbenennen   */
  144.          exit();
  145.       default :
  146.          fault(5,"");                                  /*   Eingabefeher   */
  147.    }
  148. }
  149.